CC = gcc
AFLAGS = -c -g
LDFLAGS= -lpaho-mqtt3c -lrt -lm -lpthread
OBJS = func.o main.o mqtt.o
HAAS_LIB = libhaas.a

all:server lib

server:$(OBJS)
	$(CC) -o $@ $^ $(LDFLAGS)
	
%.o:%.c
	$(CC) $(AFLAGS) $< -o $@

.PHONY:clean lib publish
clean:
	rm -rf *.o *exe* *.a server
	rm -rf ../publish/*

lib:
	ar crs $(HAAS_LIB) $(OBJS)

#把对外公开的文件和库自动打包
OS_TYPE := $(shell uname -m)

publish:
	rm -rf ../publish/*
	cp $(HAAS_LIB) ../publish
	cp *.h ../publish
	cp Makefile_pub ../publish/Makefile
ifeq ($(OS), Windows_NT)
	@echo Cygwin64环境不需要拷贝MQTT库
else
ifeq ($(OS_TYPE), x86_64)
	@echo 64
	cp -r ./lib/x64 ../publish/lib
else
	cp -r ./lib/x32 ../publish/lib
endif
	cp -r ./include ../publish
endif

install_paho:
ifeq ($(OS), Windows_NT)
	@echo Cygwin64环境不需要拷贝MQTT库
else
ifeq ($(OS_TYPE), x86_64)
	@echo 64
	sudo cp ./lib/x64/*.so* /usr/lib -d
else
	sudo cp ./lib/x32/*.so* /usr/lib -d
endif
	sudo cp ./include/*.h /usr/include/
endif